//
//  ViewController.m
//  04-Homework
//
//  Created by dllo on 16/7/19.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface ViewController ()
@property (nonatomic, strong) UILabel *changedTime;
@property (nonatomic, strong) UILabel *endTime;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    backgroundImageView.image = [UIImage imageNamed:@"vc_bg"];
    [self.view addSubview:backgroundImageView];
    [self creatSubViews];
}

- (void)creatSubViews {
    UIButton *miniButton = [UIButton buttonWithType:UIButtonTypeCustom];
  
    [miniButton setImage:[UIImage imageNamed:@"miniplayer_btn_playlist_close_b"] forState:UIControlStateNormal];
    [self.view addSubview:miniButton];
    
    UIButton *allMusicButton = [UIButton buttonWithType:UIButtonTypeCustom];
    allMusicButton.frame = CGRectMake(self.view.frame.size.width - 50, 10, 50, 50);
    [allMusicButton setImage:[UIImage imageNamed:@"allMusic_more"] forState:UIControlStateNormal];
    [self.view addSubview: allMusicButton];
    
    UILabel *songNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH * 0.38, 25, WIDTH * 0.3, 20)];
    songNameLabel.text = @"阿猫阿狗";
    songNameLabel.textColor = [UIColor whiteColor];
    songNameLabel.font = [UIFont systemFontOfSize:25];
    [self.view addSubview:songNameLabel];
    
    UILabel *authorLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH * 0.45, 50, WIDTH * 0.2, 20)];
    authorLabel.textColor = [UIColor whiteColor];
    authorLabel.text = @"陈奕迅";
    [self.view addSubview:authorLabel];
    
    UIButton *freeWifiButton = [UIButton buttonWithType:UIButtonTypeCustom];
    freeWifiButton.frame = CGRectMake(WIDTH * 0.2, HEIGHT * 0.13, WIDTH * 0.18, 25);
    [freeWifiButton setBackgroundImage:[UIImage imageNamed:@"player_btn_chinaunicom_normal"] forState:UIControlStateNormal];
    [freeWifiButton setBackgroundImage:[UIImage imageNamed:@"player_btn_chinaunicom_highlight"] forState:UIControlStateHighlighted];
    [self.view addSubview:freeWifiButton];
    
    UIButton *sqlButton = [UIButton buttonWithType:UIButtonTypeCustom];
    sqlButton.frame = CGRectMake(freeWifiButton.frame.size.width + freeWifiButton.frame.origin.x + 10, freeWifiButton.frame.origin.y, WIDTH * 0.15, freeWifiButton.frame.size.height);
    [sqlButton setBackgroundImage:[UIImage imageNamed:@"player_btn_sq_sel_normal"] forState:UIControlStateNormal];
    [sqlButton setBackgroundImage:[UIImage imageNamed:@"player_btn_sq_sel_highlight"] forState:UIControlStateHighlighted];
    [self.view addSubview:sqlButton];
    
    UIButton *mvButton = [UIButton buttonWithType:UIButtonTypeCustom];
    mvButton.frame = CGRectMake(sqlButton.frame.size.width + sqlButton.frame.origin.x + 10, sqlButton.frame.origin.y, WIDTH * 0.1, sqlButton.frame.size.height);
    [mvButton setBackgroundImage:[UIImage imageNamed:@"player_btn_mv_normal"] forState:UIControlStateNormal];
    [mvButton setBackgroundImage:[UIImage imageNamed:@"player_btn_mv_highlight"] forState:UIControlStateHighlighted];
    [self.view addSubview:mvButton];
    
    UIButton *dtsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    dtsButton.frame = CGRectMake(mvButton.frame.origin.x + mvButton.frame.size.width + 10, mvButton.frame.origin.y, mvButton.frame.size.width, mvButton.frame.size.height);
    [dtsButton setBackgroundImage:[UIImage imageNamed:@"player_btn_dts_off"] forState:UIControlStateNormal];
    [self.view addSubview:dtsButton];
    
    UIImageView *photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * 0.05, HEIGHT * 0.20, 280, 280)];
    photoImageView.image = [UIImage imageNamed:@"the_key"];
    photoImageView.layer.cornerRadius = 140;
    photoImageView.layer.masksToBounds = YES;
    [self.view addSubview:photoImageView];
    
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(WIDTH * 0.15, HEIGHT * 0.7, WIDTH * 0.7, 20)];
    slider.minimumValue = 0.00f;
    slider.maximumValue = 3.49f;
    [slider setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:UIControlStateNormal];
    [slider setMaximumTrackImage:[UIImage imageNamed:@"player_slider_playback_ritght"] forState:UIControlStateNormal];
    [slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb"] forState:UIControlStateNormal];
    [slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:slider];
    
    self.changedTime = [[UILabel alloc] initWithFrame:CGRectMake(10, HEIGHT * 0.7, WIDTH * 0.15, 20)];
    _changedTime.textColor = [UIColor whiteColor];
    _changedTime.text = @"00:00";
    [self.view addSubview:_changedTime];
    
    self.endTime = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH * 0.86, _changedTime.frame.origin.y, _changedTime.frame.size.width, _changedTime.frame.size.height)];
    _endTime.text = [NSString stringWithFormat:@"0%.2f", slider.maximumValue];
    _endTime.textColor = _changedTime.textColor;
    [self.view addSubview:_endTime];
    
    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH * 0.48, HEIGHT * 0.65, 20, 20)];
    pageControl.numberOfPages = 3;
    [self.view addSubview:pageControl];
    
    // 播放相关button
    UIButton *preButton = [UIButton buttonWithType:UIButtonTypeCustom];
    preButton.frame = CGRectMake(WIDTH * 0.18, HEIGHT * 0.76, 70, 70);
    [preButton setBackgroundImage:[UIImage imageNamed:@"player_btn_pre_normal"] forState:UIControlStateNormal];
    [preButton setBackgroundImage:[UIImage imageNamed:@"player_btn_pre_highlight"] forState:UIControlStateHighlighted];
    [self.view addSubview:preButton];
    
    UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    playButton.frame = CGRectMake(WIDTH * 0.4, preButton.frame.origin.y, 80, 80);
    [playButton setBackgroundImage:[UIImage imageNamed:@"player_btn_play_normal"] forState:UIControlStateNormal];
    [playButton setBackgroundImage:[UIImage imageNamed:@"player_btn_play_highlight"] forState:UIControlStateHighlighted];
    [playButton addTarget:self action:@selector(playButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:playButton];
    
    UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    nextButton.frame = CGRectMake(WIDTH * 0.65, playButton.frame.origin.y, 70, 70);
    [nextButton setBackgroundImage:[UIImage imageNamed:@"player_btn_next_normal"] forState:UIControlStateNormal];
    [nextButton setBackgroundImage:[UIImage imageNamed:@"player_btn_next_highlight"] forState:UIControlStateHighlighted];
    [self.view addSubview:nextButton];
    
    // 底部五个button
    NSArray *normalImages = @[@"player_btn_favorited_normal", @"player_btn_repeat_highlight", @"player_btn_downloaded_normal_1", @"player_btn_share_normal", @"player_btn_playlist_normal"];
    NSArray *highlightImages = @[@"player_btn_favorited_highlight", @"player_btn_repeat_highlight", @"player_btn_downloaded_highlight", @"player_btn_share_highlight", @"player_btn_playlist_highlight"];
    for (int i = 0; i < 5; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(10 + 75 * i, HEIGHT * 0.9, 60, 60);
        [button setBackgroundImage:[UIImage imageNamed:normalImages[i]] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:highlightImages[i]] forState:UIControlStateHighlighted];
        button.tag = 1001 + i;
        [self.view addSubview:button];
    }

}

- (void)sliderValueChanged:(UISlider *)slider {
    _changedTime.text = [NSString stringWithFormat:@"0%.2f", slider.value];
}

- (void)playButtonDidClicked:(UIButton *)button {
    [button removeTarget:self action:@selector(playButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundImage:[UIImage imageNamed:@"player_btn_pause_normal"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"player_btn_pause_highlight"] forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(pauseButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)pauseButtonDidClicked:(UIButton *)button {
    [button removeTarget:self action:@selector(pauseButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundImage:[UIImage imageNamed:@"player_btn_play_normal"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"player_btn_play_normal_highlight"] forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(playButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
